package cn.wjdiankong.levideo.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.wjdiankong.levideo.R;
import cn.wjdiankong.levideo.utils.AdUtils;
import cn.wjdiankong.levideo.utils.AdUtils.AdListener;
import cn.wjdiankong.levideo.utils.UmengReportUtils;
import cn.wjdiankong.levideo.utils.Utils;

public class SplashActivity extends BaseActivity{

	private RelativeLayout mNativeSpotAdLayout;
	private ImageView splashImg;
	private TextView versionTxt;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		initView();
		initData();
		isGestureFinish = false;
	}

	public void initView(){
		super.initView();
		mNativeSpotAdLayout = (RelativeLayout) findViewById(R.id.layout_ad);
		splashImg = (ImageView) findViewById(R.id.splash_img);
		versionTxt = (TextView) findViewById(R.id.version_txt);
		findViewById(R.id.entry).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				UmengReportUtils.report(UmengReportUtils.SPLASH_ENTER);
				MainActivity.startDefault(SplashActivity.this);
				finish();
			}
		});
	}

	protected void initData(){
		super.initData();
		AdUtils.preLoadVideoAd();
		versionTxt.setText("v "+Utils.getVersion(getApplicationContext()));
		getNativeAd();
	}

	public void getNativeAd(){
		AdUtils.showSplashAd(mNativeSpotAdLayout, new AdListener() {
			@Override
			public void showSucc() {
				splashImg.setVisibility(View.GONE);
			}
			
			@Override
			public void showFail() {
				splashImg.setVisibility(View.VISIBLE);
			}
			
			@Override
			public void close() {
			}
			
			@Override
			public void click() {
				
			}
		});
	}

	@Override
	protected String getPageName() {
		return "splash";
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		// 开屏展示界面的 onDestroy() 回调方法中调用
        //SpotManager.getInstance(getApplicationContext()).onDestroy();
	}
	
	/** 
	 * 菜单、返回键响应 
	 */  
	@Override  
	public boolean onKeyDown(int keyCode, KeyEvent event) {  
		if(keyCode == KeyEvent.KEYCODE_BACK)  { 
			UmengReportUtils.report(UmengReportUtils.SPLASH_BACK);
			MainActivity.startDefault(this);
			finish();
		}  
		return false; 
	}  
	
}
